#ifndef _USERS_TIMERS_H_
#define _USERS_TIMERS_H_

#include "types.h"
#include "queue.h"
#include "err.h"


typedef enum
{
    TIMER_REQUESTED,
    TIMER_RUNNING,
    TIMER_CANCELLED,
    TIMER_EXPIRED,
    TIMER_PROCESSED,
}timer_state_t;

typedef struct
{
    queue_msg_type_t msg_id;
    struct _queue_msg_t *next;

    /*
    * User filled params
    */
    uint32_t interval;    // periodic
    bool periodic;
    void (*user_handler)(void *);
    void *user_handler_arg;

    /*
    * Queue to which to post the 
    * timer expiry message
    */
    q_id_t q_id;



    timer_state_t state;
    queue_t *q_handle;
    uint32_t pid;

    // return parameter
    err_t timer_err;
    void *platform_handle;  // context for cancelling the timer at platform


}user_timer_data_t;

err_t user_timer_start(user_timer_data_t *timer_data);
err_t user_timer_cancel(user_timer_data_t *user_timer_handle);

#endif
